package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.entity.NursingProject;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ Description NursingProjectController
 * @ Author zhengsuhang
 * @ Date 2025-05-08  11:01
 */
@RestController
@Api(tags = "护理项目管理")
@RequestMapping("/nursing_project")
public class NursingProjectController extends BaseController{
    @Autowired
    private NursingProjectService nursingProjectService;

    /**
     * 护理项目分页查询
     * @param nursingProjectDto
     * @return
     */
    @GetMapping
    @ApiOperation(value = "分页查询", notes = "传入护理项目名称,当前页码,每页显示条数,状态（0：禁用，1：启用）")
    public ResponseResult<PageResponse<NursingProjectVo>> pageNursingProjectQuery(NursingProjectDto nursingProjectDto){
        // 调用Service层实现分页查询,并且封装成分页的PageResponse<T>的对象,相当于之前的PageBean
        PageResponse<NursingProjectVo> pageResponse = nursingProjectService.pageNursingProjectQuery(nursingProjectDto);
        // 返回统一的响应结果
        return success(pageResponse);
    }

    /**
     * 新增护理项目
     * @param nursingProject
     * @return
     */
    @PostMapping
    @ApiOperation(value = "创建床位", notes = "新增项目的基础信息，必填字段：床位名称、价格、计价单位；选填字段：图片、护理要求、排序号、备注、启用状态")
    public ResponseResult addNursingProject(@RequestBody NursingProject nursingProject){
        // 调用业务层进行新增
        nursingProjectService.addNursingProject(nursingProject);
        // 统一返回响应结果
        return success();
    }


    /**
     * 根据id查询护理项目
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查询护理项目", notes = "传入护理项目的id")
    public ResponseResult<NursingProjectVo> getById(@ApiParam(value = "id")@PathVariable Integer id){
        // 调用Service层根据id回显数据
        NursingProjectVo nursingProjectVo =  nursingProjectService.getById(id);
        // 统一返回响应的数据
        return success(nursingProjectVo);
    }

    /**
     * 更新护理项目
     * @param nursingProject
     * @return
     */
    @PutMapping
    @ApiOperation(value = "更新护理项目", notes = "传入护理项目的基础信息，必填字段：床位名称、价格、计价单位；选填字段：图片、护理要求、排序号、备注、启用状态")
    public ResponseResult updateNursingProject(@RequestBody NursingProject nursingProject){
        // 调用Service层更新护理项目
        nursingProjectService.updateNursingProject(nursingProject);
        // 统一返回响应的数据
        return success();
    }

    /**
     * 启用禁用
     * @param id
     * @param status
     * @return
     */
    @PutMapping("/{id}/status/{status}")
    @ApiOperation(value = "启用禁用", notes = "传入项目Id和项目状态(0：禁用，1：启用)")
    public ResponseResult setSwitchStatus(@ApiParam(value = "id") @PathVariable Long id, @ApiParam(value = "status") @PathVariable Integer status){
        // 调用Service层设置状态
        nursingProjectService.setSwitchStatus(id, status);
        // 统一返回响应的数据
        return success();
    }

    /**
     * 查询所有护理项目
     * @return
     */
    @GetMapping("/all")
    @ApiOperation(value = "查询所有护理项目")
    public ResponseResult<List<NursingProjectVo>> findAll(){
        // 调用Service层查询所有护理项目
        List<NursingProjectVo> list = nursingProjectService.findAll();
        // 统一返回响应的数据
        return success(list);
    }

}
